package com.yisearch.search.doSearch.service.impl;

import com.yisearch.search.base.constant.ESConstant;
import com.yisearch.search.doSearch.service.DoSearchService;
import com.yisearch.search.utils.ImportDataUtil;
import org.frameworkset.elasticsearch.boot.BBossESStarter;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.frameworkset.elasticsearch.entity.ESDatas;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("productService")
public class ProductSearchImpl implements DoSearchService {

    @Autowired
    private BBossESStarter bBossESStarter;

    @Override
    public Map<String, Object> importFullData(Map<String, Object> params) {
        try {
            ImportDataUtil.fullImportData(false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Map<String, Object> doSearch(Map<String, Object> params) {
        Map ret = new HashMap();
        ClientInterface client = bBossESStarter.getConfigRestClient(ESConstant.EsIndexName.SEARCH_PRODUCT_DSLMAPPING_PATH);
        ESDatas<Object> esDatas = client.searchList("/product/_search", "searchProducts", params, Object.class);
        List list = esDatas.getDatas();
        ret.put("list", list);
        return ret;
    }
}
